/*
 * @Author: 生俊甫 1758142861@qq.com
 * @Date: 2025-01-14 16:07:14
 * @LastEditors: 生俊甫 1758142861@qq.com
 * @LastEditTime: 2025-01-14 16:14:35
 * @FilePath: /sjf/weChat_project/test_to_there/framework/spdlog_test/async.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <iostream>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/async.h>

/**
 * 异步日志器
 */
int main()
{ 
    //设置全局的刷新策略(每秒刷新)
    spdlog::flush_every(std::chrono::seconds(1));
    //设置为debug以上级别时进行刷新
    spdlog::flush_on(spdlog::level::level_enum::debug);
    //设置全局的日志输出等级
    spdlog::set_level(spdlog::level::level_enum::debug);
    //创建同步日志器(io/file) -- 工厂接口默认创建的是同步日志器
    //auto logger = spdlog::stdout_color_mt("default-logger");
    
    /**
     * 异步可以设置线程数量
     * lnline void init_thread_pool(size_t q_size, size_t thread_count) 
     * q_size:表示的是节点数量
     * thread_count:表示的线程数量
     */
    spdlog::init_thread_pool(2000,1);
    auto logger = spdlog::basic_logger_mt<spdlog::async_factory>("file-logger","async.log");
    //设置日志器的刷新策略和输出等级
    // logger->flush_on(spdlog::level::level_enum::debug);
    // logger->set_level(spdlog::level::level_enum::debug);
    //设置日志输出的格式
    logger->set_pattern("[%Y-%m-%d %H:%M:%S][%t][%-8l]%v");
    //test
    logger->trace("this is a trace message");
    logger->debug("this is a debug message");
    logger->info("This is an info message"); 
    logger->warn("This is a warning message"); 
    logger->error("This is an error message"); 
    logger->critical("This is a critical message");
    std::cout << "success" << std::endl;
    return 0;
}